<template>
	<view class="waterElectricityBill_box boxFormat">
		<view class="waterElectricityBill_container">
			<topBar></topBar>
			<view class="waterElectricityBill_container_bottom">
				<view class="waterElectricityBill_container_bottom_item" v-for="(item,index) in waterElectricityBillArr"
					:key="index" @click="gotoMyMeter(item,index)">
					<view class="waterElectricityBill_container_bottom_item_name">
						{{item.name}}
					</view>
					<view class="waterElectricityBill_container_bottom_item_container">
						<view class="waterElectricityBill_container_bottom_item_container_number">
							<view class="">
								可用金额： {{item.money}}元
							</view>
							<view class="" v-if="item.money>0">
								用电状态：<p style="color: green;float: right;">{{item.state}}</p>
							</view>
							<view class="" v-if="item.money==0">
								用电状态：<p style="color: orange;float: right;">{{item.state}}</p>
							</view>
							<view class="" v-if="item.money<0">
								用电状态：<p style="color: darkred;float: right;">{{item.state}}</p>
							</view>
						</view>
						<view class="">
							<uni-icons type="right" size="20"></uni-icons>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import topBar from "../../component/topBar/topBar.vue"
	import {
		findDormitoryById
	} from "../../api/request.js"
	export default {
		data() {
			return {
				waterElectricityBillArr: [],
				dormitoryId: null
			};
		},
		components: {
			topBar
		},
		onLoad() {
			const that = this
			uni.getStorage({
				key: "dormitoryId",
				success(res) {
					that.dormitoryId = res.data
					that.findDormitoryByIdMethod()
				}
			})
		},
		methods: {
			async findDormitoryByIdMethod() {
				let res = await findDormitoryById(this.dormitoryId)
				console.log(res);
				const {
					electricityBillMoney,
					electricityBillStatus,
					hotWaterMoney,
					hotWaterStatus,
					waterCostMoney,
					waterCostStatus
				} = res.data
				this.waterElectricityBillArr.push({
					id: 105,
					name: "电费",
					money: electricityBillMoney,
					state: electricityBillStatus,
					type: "Electricity"
				}, {
					id: 106,
					name: "热水",
					money: hotWaterMoney,
					state: hotWaterStatus,
					type: 'hotWater'
				}, {
					id: 104,
					name: "水费",
					money: waterCostMoney,
					state: waterCostStatus,
					type: 'water'
				})
			},
			gotoMyMeter(item, index) {
				console.log(item, index);
				if (item.type == "Electricity") {
					getApp().globalData.moneyType = "electricity"
					getApp().globalData.status = this.waterElectricityBillArr[0].state
					getApp().globalData.money = this.waterElectricityBillArr[0].money
					uni.navigateTo({
						url: "/pages/myElectricityMeter/myElectricityMeter?type=electricity"
					})
				}
				if (item.type == "hotWater") {
					getApp().globalData.status = this.waterElectricityBillArr[1].state
					getApp().globalData.money = this.waterElectricityBillArr[1].money
					getApp().globalData.moneyType = "hotWater"
					uni.navigateTo({
						url: "/pages/myElectricityMeter/myElectricityMeter?type=hotWater"
					})
				}
				if (item.type == "water") {
					getApp().globalData.status = this.waterElectricityBillArr[2].state
					getApp().globalData.money = this.waterElectricityBillArr[2].money
					getApp().globalData.moneyType = "water"
					uni.navigateTo({
						url: "/pages/myElectricityMeter/myElectricityMeter?type=water"
					})
				}
			}
		}
	}
</script>

<style lang="less">
	.redeMore {
		width: 186.96rpx;
		height: 70.16rpx;
		background: rgba(255, 255, 255, 1);
		border-radius: 20rpx;
	}

	.index_container_top {
		margin-bottom: 40rpx;
		box-shadow: 0rpx 74.49rpx 126.64rpx rgba(11, 61, 212, 0.27);
		border-radius: 20rpx;
		overflow: hidden;

		.index_container_top_container {
			background: url("../../static/bg3.png") no-repeat;
			background-size: 100%;
			width: 87%;
			height: 413.17rpx;
			background-size: cover;
			background-position: center;
			-webkit-transform: scale(1.1);
			transform: scale(1.1);
			padding: 20rpx;
			margin: auto;
			border-radius: 21.5rpx;

			/* 将背景图片定位到元素的中心 */
			.index_container_top_container_title {
				font-size: 30.93rpx;
				font-weight: 500;
				letter-spacing: 0rpx;
				line-height: 52.03rpx;
				color: rgba(255, 255, 255, 1);
				text-align: left;
				vertical-align: top;
			}

			.index_container_top_container_welcome {
				font-size: 33.68rpx;
				font-weight: 400;
				letter-spacing: 0rpx;
				line-height: 48.77rpx;
				color: rgba(255, 255, 255, 1);
				text-align: left;
				vertical-align: top;
			}
		}
	}

	.waterElectricityBill_box {
		width: 100%;
		height: 100vh;

		.waterElectricityBill_container {
			width: 90%;
			margin: auto;

			.waterElectricityBill_container_bottom {
				display: flex;
				flex-direction: column;
				margin-top: 60rpx;

				.waterElectricityBill_container_bottom_item {
					display: flex;
					flex-direction: column;
					background-color: white;
					margin-bottom: 20rpx;
					border-radius: 30rpx;

					.waterElectricityBill_container_bottom_item_name {
						padding: 6rpx 14rpx;
						border: 1px solid #4F73FB;
						width: 120rpx;
						border-radius: 14rpx;
						color: #4F73FB;
						text-align: center;
						font-weight: 600;
						margin-bottom: 20rpx;
						margin-top: 20rpx;
						margin-left: 20rpx;
					}

					.waterElectricityBill_container_bottom_item_container {
						display: flex;
						justify-content: space-between;
						margin-bottom: 20rpx;

						.waterElectricityBill_container_bottom_item_container_number {
							margin-left: 60rpx;
							display: flex;
							flex-direction: column;
							font-size: 30rpx;

							>view {
								margin-bottom: 20rpx;
							}
						}
					}
				}
			}
		}
	}
</style>